package com.yphone.ui.dialog;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;

import com.zzkj.yunphone.R;
import com.yphone.tools.Constants;
import com.yphone.ui.dialog.inf.IAlterDisCallBack;
import com.yphone.utils.NetworkUtils;
import com.yphone.utils.RegexUtils;
import com.yphone.utils.ToastUtils;

public class AlterDisDialog extends BaseDialog implements OnClickListener {
    public static AlterDisDialog alterDisDialog;
    private String dis;
    private TextView mCentent;
    private IAlterDisCallBack mCllaBack;
    private Context mContext;
    private EditText mEdit;
    private TextView mOkBtn;

    public static void showDialog(final Context context, final String dis2, boolean isLock, final IAlterDisCallBack cllBack) {
        if (isLock) {
//            DeviceLock9Dialog.showDialog(context, new IDeviceLock9View() {
//                public void LockSuccess(String msg) {
//                    DeviceLock9Dialog.dissmissDialog();
//                    AlterDisDialog.showDialog(context, dis2, cllBack);
//                }
//
//                public void LockFail(String msg) {
//                    if (!TextUtils.isEmpty(msg)) {
//                        ToastUtils.showLong((CharSequence) msg);
//                    }
//                }
//            });
        } else {
            showDialog(context, dis2, cllBack);
        }
    }

    /* access modifiers changed from: private */
    public static AlterDisDialog showDialog(Context context, String dis2, IAlterDisCallBack cllBack) {
        if (alterDisDialog == null) {
            alterDisDialog = new AlterDisDialog(context, dis2, cllBack);
        }
        alterDisDialog.show();
        return alterDisDialog;
    }

    public AlterDisDialog(Context context, String fistdis, IAlterDisCallBack cllBack) {
        super(context, R.style.NoTitleDialog);
        this.mContext = context;
        this.mCllaBack = cllBack;
        this.dis = fistdis;
        setCanceledOnTouchOutside(false);
    }

    public void initView() {
        setContentView(R.layout.dialog_alter_dis);
        this.mEdit = (EditText) findViewById(R.id.pop_edit_alter_dis_order);
        this.mCentent = (TextView) findViewById(R.id.pop_centen_alter_dis_order);
        this.mOkBtn = (TextView) findViewById(R.id.pop_ok_alter_dis_order);
    }

    public void initData() {
        setCancelable(false);
        this.mEdit.requestFocus();
        this.mEdit.setText(this.dis);
        if (this.dis != null && !this.dis.equals("")) {
            this.mEdit.setSelection(this.dis.length());
        }
    }

    public void initListener() {
        this.mCentent.setOnClickListener(this);
        this.mOkBtn.setOnClickListener(this);
    }

    public void dismiss() {
        super.dismiss();
        alterDisDialog = null;
    }

    public static void dissmissDialog() {
        if (alterDisDialog != null) {
            alterDisDialog.dismiss();
        }
    }

    public void onClick(View view) {
        int id = view.getId();
        if (id == this.mCentent.getId()) {
            dissmissDialog();
        }
        if (id != this.mOkBtn.getId()) {
            return;
        }
        if (!NetworkUtils.isConnected()) {
            ToastUtils.showLong((CharSequence) "保存失败，请检查网络后重试");
        } else if ("".equals(this.mEdit.getText().toString().trim())) {
            this.mCllaBack.callback(this.mEdit.getText().toString().trim());
            dissmissDialog();
        } else if (!RegexUtils.isMatch(Constants.NICK_MATCHING, this.mEdit.getText().toString().trim())) {
            ToastUtils.showLong((CharSequence) this.mContext.getString(R.string.alter_dis));
        } else {
            this.mCllaBack.callback(this.mEdit.getText().toString().trim());
            dissmissDialog();
        }
    }
}